﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="ImagesUpload.aspx.cs" Inherits="Admin_Views_ImagesUpload" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<script type="text/javascript" src="../../js/jquery-1.6.min.js"></script>
<script type="text/javascript" src="../js/swfuploader/swfupload.js?v=2.5"></script>

<script type="text/javascript">
    var DarrenUpload = function (options) {
        if (typeof (options) == "string") {
            options = { button_placeholder_id: options };
        }

        var _options = $.extend({
            script: "../handlers/saveImage.ashx",
            folder: "../UploadFiles",
            file_size_limit: "30 MB",
            fileExt: "*.jpg;*.png;*.gif",
            file_types_description: "JPG Images; PNG Image; Gif Image",
            file_widthheight: [500, 500],
            buttonText: "Upload Images",
            id: "",
            scriptData: {}, //附加参数
            onUploadStart: $.noop,
            onError: $.noop,
            onComplete: $.noop
        }, options);

        $.extend(_options.scriptData, { folder: _options.folder });
        return new SWFUpload({
            upload_url: _options.script,
            post_params: _options.scriptData,
            // File Upload Settings
            file_size_limit: _options.file_size_limit,
            file_types: _options.fileExt,
            file_types_description: _options.file_types_description,
            file_upload_limit: 100,
            file_widthheight: _options.file_widthheight,  //缩放图片[w,h]

            swfupload_preload_handler: function () {
                if (!this.support.loading) {
                    alert("You need the Flash Player to use SWFUpload.");
                    return false;
                } else if (!this.support.imageResize) {
                    alert("You need Flash Player 10 to upload resized images.");
                    return false;
                }
            },
            swfupload_load_failed_handler: function () {
                alert("Something went wrong while loading SWFUpload. If this were a real application we'd clean up and then give you an alternative");
            },
            upload_start_handler: _options.onUploadStart,
            file_dialog_complete_handler: function (numFilesSelected, numFilesQueued) {
                if (numFilesQueued > 0) {
                    var t = this;
                    var i = 0;
                    for (i = 0; i < numFilesQueued; i++) {
                        t.startResizedUpload(t.getFile(i).ID, t.settings.file_widthheight[0], t.settings.file_widthheight[1], SWFUpload.RESIZE_ENCODING.JPEG, 95);
                    }
                }
            }, //选择对话框关闭事件
            upload_error_handler: _options.onError, //上传失败事件
            upload_success_handler: _options.onComplete, //单个文件上传成功事件

            button_placeholder_id: _options.id,
            button_width: 100,
            button_height: 25,
            button_action: SWFUpload.BUTTON_ACTION.SELECT_FILE,  //单图片上传
            button_text: _options.buttonText,
            button_text_left_padding: 2,
            button_text_top_padding: 2,


            button_window_mode: SWFUpload.WINDOW_MODE.TRANSPARENT,
            button_cursor: SWFUpload.CURSOR.HAND,

            // Flash Settings
            flash_url: "../js/swfuploader/swfupload.swf",
            flash9_url: "../js/swfuploader/swfupload_fp9.swf"


        });
    }

    $(function () {
        DarrenUpload({
            id: "aaa",
            onUploadStart: function () { $("#message").html("正在上传..") },
            onComplete: function (file, serverData) { $("#message").html("上传成功，返回:" + serverData) },
            onError: function () { }
        });
    });
</script>
</head>
<body>
    <form id="form1" runat="server">
        <span id="aaa"></span>
        <div id="message"></div>
    </form>
</body>
</html>
